<?php
class Plus_Form_Admin_Country_Edit extends Zend_Form implements Plus_Form_Admin_Interface_Edit
{	
	protected $_idField;
	
	public function init()
	{
		$this->setMethod('post');
		$this->_idField = 'country';
		//$this->setAction('ccc');
		/*
		$this->addElement('text', 'Name', array(
			'label' 	=> 'Country name:',
			'required' 	=> true
		));
		
		$this->addElement('checkbox', 'IsEnabled', array(
			'label'	=> 'Enable this country for users?',
			'checked' => true
		));
		
		$this->addElement('submit', 'submit', array(
			'ignore'	=> true,
			'label'		=> 'Add country'
		));
		
		$this->addElement('hash', 'csrf', array(
			'ignore'	=> true
		));*/
	}
	
	public function getIdFieldName()
	{
		return $this->_idField;
	}
	
	public function makeList(array $countries)
	{
		$this->setAction('/admin/countryEdit');
		
		//var_dump($countries);
		$multiOptions = array();
		foreach ($countries as $country) {
			$multiOptions[$country->getId()] = $country->getName();
		}	
		$this->addElement('select', $this->getIdFieldName(), array(
			'label' => 'Choose country You wish to edit',
			'multioptions' => $multiOptions
		));
		
		$this->addElement('submit', 'doEdit', array(
			'ignore'	=> true,
			'label'		=> 'Edit selected country'
		));
		
		$this->addElement('submit', 'doDelete', array(
			'ignore'	=> true,
			'label'		=> 'Delete selected country',
			'value'		=> true
		));
	}
	
	public function makeEdit(Plus_Model_Model_Abstract $country)
	{
		$this->setAction('/admin/countryUpdate');
		
		$this->addElement('text', 'Name', array(
			'label' 	=> 'Country name:',
			'required' 	=> true,
			'value'		=> $country->getName()
		));
		
		$this->addElement('checkbox', 'IsEnabled', array(
			'label'		=> 'Enable this country for users?',
			'checked' 	=> true,
			'value'		=> $country->getIsEnabled()
		));
		
		$this->addElement('submit', 'submit', array(
			'ignore'	=> true,
			'label'		=> 'Update country data'
		));
		
		$this->addElement('reset', 'reset', array(
			'label'		=> 'Reset changes'
		));
		
		$this->addElement('hash', 'csrf', array(
			'ignore'	=> true
		));
		
		/*$this->addElement('hidden', 'IdName', array(
			'value'		=> $country->getIdName()		
		));*/
		
		$this->addElement('hidden', $this->getIdFieldName(), array(
			'value'		=> $country->getId()		
		));
	}
}